<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../layuimini-2/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuimini-2/css/layuimini.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">就餐人姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="dinName" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">食物风格</label>
        <div class="layui-input-inline">
            <select name="foodStyle" lay-verify="">
                <option value="">-----</option>
                <option value="1">中餐</option>
                <option value="2">西餐</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">味道</label>
        <div class="layui-input-inline">
            <select name="taste" lay-verify="">
                <option value="">---</option>
                <option value="1">美味</option>
                <option value="2">一般</option>
                <option value="3">不好</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">价格</label>
        <div class="layui-input-inline">
            <input type="text" name="price" lay-verify="required" lay-reqtext="价格不能为空" placeholder="请输入价格" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">就餐时间</label>
        <div class="layui-input-inline">
            <input type="text" name="diningTime" id="diningTime" lay-verify="required" lay-reqtext="就餐时间不能为空" placeholder="请输入就餐时间" value="" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>

<script src="../../../layuimini-2/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form',"laydate"], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate= layui.laydate,
            $ = layui.$;

        laydate.render({
            elem:'#diningTime' //指定元素
        });


        //监听提交
        form.on('submit(saveBtn)', function (obj) {

            $.ajax({
                url:"/dining/add.do",
                type:"POST",
                data:obj.field,
                success:function (ret) {
                    console.log("ret ==>",ret.code);
                    if (ret.code == 0) {
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    } else {
                        layer.msg("添加失败!")
                    }
                },
                error:function (){
                    layer.msg("服务器正忙!")
                }
            })
            return false;
            // var index = layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // }, function () {
            //     // 关闭弹出层
            //     layer.close(index);
            //     var iframeIndex = parent.layer.getFrameIndex(window.name);
            //     parent.layer.close(iframeIndex);
            // });
            // return false;
        });

    });
</script>
</body>
</html>